package com.videoanswer.van.web.client.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.videoanswer.van.web.client.model.ForecastCourse;
import com.videoanswer.van.web.client.utils.Pager;


@Controller
public class OverviewController  {
	
	/*
	 * van overview page
	 */
	@RequestMapping(value = { "/overview" , "/"}, method = {RequestMethod.GET})
	public ModelAndView overview(HttpServletRequest request, HttpServletResponse response, 
			ModelMap model,HttpSession session) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		
		return new ModelAndView("/overview", map);
	}
	
	@RequestMapping(value = { "/forecastCourseDetail"}, method = {RequestMethod.GET})
	public ModelAndView getForecastCourseDetail(HttpServletRequest request, HttpServletResponse response, 
			ModelMap model,HttpSession session) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hasMainNav", false);
		
		return new ModelAndView("/course/forecastCourseDetail", map);
	}
	
	@RequestMapping(value = { "/watchOldCourse"}, method = {RequestMethod.GET})
	public ModelAndView getOldCourseDetail(HttpServletRequest request, HttpServletResponse response, 
			ModelMap model,HttpSession session) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hasMainNav", false);
		
		return new ModelAndView("/course/watchOldCourse", map);
	}
	
	@RequestMapping(value = { "/overviewTextNews"}, method = {RequestMethod.GET})
	public ModelAndView getTextNews(HttpServletRequest request, HttpServletResponse response, 
			ModelMap model,HttpSession session) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hasMainNav", false);
		
		return new ModelAndView("/textNews/overviewTextNews", map);
	}
	
	@RequestMapping(value = { "/moreForecastCourses"}, method = {RequestMethod.GET, RequestMethod.POST})
	public ModelAndView moreForecastCourses(HttpServletRequest request, HttpServletResponse response, 
			ModelMap model,HttpSession session) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hasMainNav", false);
		
		Integer pageNum = null;
		if(null != request.getParameter("pageNum")){
			pageNum = Integer.parseInt(request.getParameter("pageNum"));
		}
		if (null == pageNum) {
			pageNum = 0;
		}
		
		Pager pager = new Pager();
		pager.setCurrentPage(pageNum);
		pager.setPerPageCount(9);
		pager.setTotalCount(52);
		pager.setTotalPage(6);
		
		List<ForecastCourse> forecastCourseList = new ArrayList<ForecastCourse>();
		
		ForecastCourse forecastCourse = new ForecastCourse();
		forecastCourse.setFeeOffline("50.00");
		forecastCourse.setFeeOnline("30.00");
		forecastCourse.setGrade("初二");
		forecastCourse.setLiveTime("2015/02/08 18:30~20:30");
		forecastCourse.setOfflineAddress("徐汇区、上师大、东区、第一教学楼");
		forecastCourse.setSubject("数学");
		forecastCourse.setTeacher("张卫");
		forecastCourse.setTheme("三角函数及其应用");
		
		if(pageNum == 0){
			forecastCourse.setCourseImgUrl("http://imgstatic.baidu.com/img/image/shouye/qinchunmeinv0808.jpg");
			for(int i=0; i<9; i++){
				forecastCourseList.add(forecastCourse);
			}
			
		}else if(pageNum == 1){
			forecastCourse.setCourseImgUrl("http://imgstatic.baidu.com/img/image/shouye/sheyiing0808.jpg");
			for(int i=0; i<9; i++){
				forecastCourseList.add(forecastCourse);
			}
			
		}else if(pageNum == 2){
			forecastCourse.setCourseImgUrl("http://imgstatic.baidu.com/img/image/shouye/menghuo0808.jpg");
			for(int i=0; i<9; i++){
				forecastCourseList.add(forecastCourse);
			}
			
		}else{
			forecastCourse.setCourseImgUrl("http://imgstatic.baidu.com/img/image/shouye/sanping4.jpg");
			for(int i=0; i<9; i++){
				forecastCourseList.add(forecastCourse);
			}
		}
		
		pager.setDatas(forecastCourseList);
		map.put("pageView", pager);
		
		return new ModelAndView("/subOverviewPages/moreForecastCourses", map);
	}
	
	@RequestMapping(value = { "/moreOldCourses"}, method = {RequestMethod.GET})
	public ModelAndView moreOldCourses(HttpServletRequest request, HttpServletResponse response, 
			ModelMap model,HttpSession session) throws Exception {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("hasMainNav", false);
		
		return new ModelAndView("/subOverviewPages/moreOldCourses", map);
	}
	
	
	
	
	
}